home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
VideoToolbox 96.06.15
/
(Utilities)
/
TestAttenuator
/
TestAttenuator.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-08-13
|
5KB
|
201 lines
/*
TestAttenuator.c
This produced a simple test pattern that allows a quick yes/no evaluation of the
attenuator before shipping. Mainly this is a check to make sure that all the
resistors were soldered correctly.
HISTORY:
11/89 dgp wrote it
9/9/90 dgp make the arrays static.
10/17/90 dgp remove unused variable
2/16/91 dgp added check for fpu and color quickdraw
8/24/91 dgp Made compatible with THINK C 5.0.
4/27/92 dgp call SetDepth to set screen to 8 bits.
8/27/92 dgp replace SysEnvirons() by Gestalt()
2/7/93 dgp updated to use SetPixelsQuickly.
*/
#include "VideoToolbox.h"
#include "Luminance.h"
#define XMAX 640 /* Maximum horizontal coordinate */
#define YMAX 480 /* Maxumum vertical coordinate */
void TestAttenuator(void);
void main(void)
{
Require(gestalt8BitQD);
TestAttenuator();
}
void TestAttenuator(void)
{
register short i,j,k;
double a,A,AA;
CWindowPtr window=NULL;
WindowPtr oldWindow=NULL;
GDHandle device=NULL,oldGDHandle=NULL;
static LuminanceRecord LR;
short n,mode;
static double fy[YMAX];
double c;
static unsigned long row[XMAX];
short oldScreen;
char string[100];
/* parameters of the screen calibration */
MaximizeConsoleHeight();
#if (THINK_C || THINK_CPLUS || SYMANTEC_C)
console_options.top=YMAX/2-40;
console_options.nrows=7;
console_options.txSize=9;
#elif __MWERKS__
SIOUXSettings.toppixel=YMAX/2-40;
SIOUXSettings.rows=7;
SIOUXSettings.columns=60;
SIOUXSettings.autocloseonquit=0;
#endif
printf("Welcome to TestAttenuator.\n");
#include "LuminanceRecord1.h" // read at compile time
printf("%s\n",LR.notes);
oldScreen=LR.screen;
i=LR.screen;
do{
if(GetScreenDevice(1)!=NULL)i=ChooseScreen(i,"Which screen?");
else i=0;
device=GetScreenDevice(i);
}while(device==NULL);
LR.screen=i;
sprintf(string,"LuminanceRecord%d.h",LR.screen);
i=ReadLuminanceRecord(string,&LR,0); // try to read latest LuminanceRecord
if(i<1)printf("Warning: couldn't find “%s”. Calibrating screen %d.\n"
,string,LR.screen);
else oldScreen=LR.screen;
/* Find device corresponding to the experimental screen. */
oldGDHandle = GetGDevice();
device = GetScreenDevice(LR.screen);
if(GDClutSize(device)!=256 && NewPaletteManager()){
mode=HasDepth(device,8,1,1);
if(mode!=0)SetDepth(device,mode,1,1); // 8-bit pixelSize, color
}
if(GDClutSize(device)!=256){
PrintfExit("Sorry, I require a screen with 256 colors.\n");
}
GetPort(&oldWindow);
window = GDOpenWindow(device);
SetPort((WindowPtr)window);
for(j=0;j<YMAX/2;j++){
fy[j]=cos(j*2.0*PI/80.0);
}
c=1.0;
SetLuminances(device,&LR,11,90,LR.LMin,LR.LMin+(LR.LMax-LR.LMin)*c);
c/=6.0;
SetLuminances(device,&LR,91,170,LR.LMin,LR.LMin+(LR.LMax-LR.LMin)*c);
c/=6.0;
SetLuminances(device,&LR,171,250,LR.LMin,LR.LMin+(LR.LMax-LR.LMin)*c);
/* Display a swept-contrast sinusoid */
for(j=0;j<YMAX/2;j++){
k=floor(0.5+79.0*0.5*c*(1.0 + fy[j]));
k+=11;
for(i=0;i<1+XMAX/3;i++)row[i]=k;
SetPixelsQuickly(0,j,row,1+XMAX/3);
}
c *=6.0;
for(j=0;j<YMAX/2;j++){
k=floor(0.5+79.0*0.5*c*(1.0 + fy[j]));
k+=91;
for(i=0;i<1+XMAX/3;i++)row[i]=k;
SetPixelsQuickly(XMAX/3,j,row,1+XMAX/3);
}
c *=6.0;
for(j=0;j<YMAX/2;j++){
k=floor(0.5+79.0*0.5*c*(1.0 + fy[j]));
k+=171;
for(i=0;i<1+XMAX/3;i++)row[i]=k;
SetPixelsQuickly(2*XMAX/3,j,row,1+XMAX/3);
}
/* compute three clut entries that ought to produce equal luminances */
AA=LToV(&LR,LR.LMax/4.0);
printf("%f cd/m^2 equivalent number is %f\n",VToL(&LR,AA),AA);
i=251;
A=AA;
a=A/LR.r;
if(a>255.) n=255;
else n=a;
LR.table[i].rgb.red=n<<8;
A -= n*LR.r;
a=A/LR.g;
if(a>255.) n=255;
else n=a;
LR.table[i].rgb.green=n<<8;
A -= n*LR.g;
a=A/LR.b;
if(a>255.) n=255;
else n=a;
LR.table[i].rgb.blue=n<<8;
A -= n*LR.b;
i++;
A=AA;
a=A/LR.g;
if(a>255.) n=255;
else n=a;
LR.table[i].rgb.green=n<<8;
A -= n*LR.g;
a=A/LR.b;
if(a>255.) n=255;
else n=a;
LR.table[i].rgb.blue=n<<8;
A -= n*LR.b;
a=A/LR.r;
if(a>255.) n=255;
else n=a;
LR.table[i].rgb.red=n<<8;
A -= n*LR.r;
i++;
A=AA;
a=A/LR.b;
if(a>255.) n=255;
else n=a;
LR.table[i].rgb.blue=n<<8;
A -= n*LR.b;
a=A/LR.r;
if(a>255.) n=255;
else n=a;
LR.table[i].rgb.red=n<<8;
A -= n*LR.r;
a=A/LR.g;
if(a>255.) n=255;
else n=a;
LR.table[i].rgb.green=n<<8;
A -= n*LR.g;
i++;
for(i=251;i<254;i++) printf("%4d,%4d,%4d = %6.2f == %7.3f cd/m^2\n",
LR.table[i].rgb.red/256,LR.table[i].rgb.green/256,LR.table[i].rgb.blue/256,
LToV(&LR,GetLuminance(NULL,&LR,i)), GetLuminance(NULL,&LR,i));
LoadLuminances(device,&LR,251,253);
/* Display stripes */
for(i=0;i<XMAX;) {
for(k=0;k<10;k++)row[i++]=251;
for(k=0;k<10;k++)row[i++]=252;
for(k=0;k<10;k++)row[i++]=253;
}
for(j=YMAX/2;j<YMAX;j++)SetPixelsQuickly(0,j,row,XMAX);
printf("Hit return to quit.");
getchar();
SetPort(oldWindow);
SetGDevice(oldGDHandle);
GDDisposeWindow(window);
RestoreCluts();
#if (THINK_C || THINK_CPLUS || SYMANTEC_C)
abort();
#elif __MWERKS__
SIOUXSettings.autocloseonquit=1;
#endif
}